chrome.runtime.onInstalled.addListener(() => {
    console.log('Extension installed');
    chrome.storage.sync.get(['memos'], (result) => {
        if (!result.memos) {
            chrome.storage.sync.set({ memos: [] });
        }
    });
});

chrome.commands.onCommand.addListener((command) => {
    console.log(`Command received: ${command}`);
    if (command === 'open-memo-extension') {
        // togglePopup();
        chrome.action.openPopup();
    }
});

// function togglePopup() {
//     if (isPopupOpen) {
//         chrome.action.setPopup({ popup: '' });
//         isPopupOpen = false;
//     } else {
//         chrome.action.setPopup({ popup: 'popup.html' });
//         isPopupOpen = true;
//     }
// }

// 处理通知
if (chrome.notifications) {
    console.log('chrome.notifications is available');
    chrome.notifications.onClicked.addListener((notificationId) => {
        console.log(`Notification clicked: ${notificationId}`);
        chrome.notifications.clear(notificationId);
    });

    chrome.notifications.onClosed.addListener((notificationId) => {
        console.log(`Notification closed: ${notificationId}`);
        chrome.notifications.clear(notificationId);
    });
} else {
    console.error('chrome.notifications is not available');
}